package com.yeskery.nut.web.demo.config;

import com.yeskery.nut.annotation.bean.Bean;
import com.yeskery.nut.annotation.bean.Configuration;
import com.yeskery.nut.annotation.condition.ConditionalOnApplicationType;
import com.yeskery.nut.annotation.condition.ConditionalOnJava;
import com.yeskery.nut.annotation.condition.ConditionalOnPlugin;
import com.yeskery.nut.application.ApplicationType;
import com.yeskery.nut.core.JavaVersion;
import com.yeskery.nut.extend.mybatisplus.MyBatisPlusPlugin;

import java.util.logging.Logger;

/**
 * 打印条件配置
 * @author YESKERY
 * 2023/9/7
 */
@Configuration
public class PrintConditionConfig {

    /** 日志对象 */
    private static final Logger logger = Logger.getLogger(PrintConditionConfig.class.getName());

    @Bean
    @ConditionalOnApplicationType(ApplicationType.WEB)
    public Print webPrint() {
        logger.info("当前运行在[WEB]环境");
        return new Print();
    }

    @Bean
    @ConditionalOnApplicationType(ApplicationType.STANDARD)
    public Print standardPrint() {
        logger.info("当前运行在[STANDARD]环境");
        return new Print();
    }

    @Bean
    @ConditionalOnPlugin(MyBatisPlusPlugin.class)
    public Print myBatisPlusPluginPrint() {
        logger.info("插件[MyBatisPlusPlugin]已加载");
        return new Print();
    }

    @Bean
    @ConditionalOnJava(JavaVersion.EIGHT)
    public Print java8Print() {
        logger.info("当前Java版本[" + JavaVersion.getJavaVersion() + "]，最低版本运行版本[1.8]");
        return new Print();
    }

    @Bean
    @ConditionalOnJava(JavaVersion.NINE)
    public Print java9OlderPrint() {
        logger.info("当前Java版本[" + JavaVersion.getJavaVersion() + "]，最低版本运行版本[9]");
        return new Print();
    }

    @Bean
    @ConditionalOnJava(range = ConditionalOnJava.Range.OLDER_THAN, value = JavaVersion.NINE)
    public Print java9Print() {
        logger.info("当前Java版本[" + JavaVersion.getJavaVersion() + "]，最高版本运行版本[9]");
        return new Print();
    }

    public static class Print {
    }
}
